from django.db import models
from django.contrib.auth.models import AbstractUser

GENDER_CHOICES = ((1, "男"), (2, "女"))


class BaseModel(models.Model):
    add_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

    class Meta:
        abstract = True


# Create your models here.
class UserEntity(AbstractUser):
    nick_name = models.CharField(max_length=48, verbose_name="昵称", default="")
    birthday = models.DateField(verbose_name="生日")
    gender = models.IntegerField(verbose_name="性别", choices=GENDER_CHOICES)
    address = models.CharField(verbose_name="地址", max_length=128, default="")
    mobile = models.CharField(verbose_name="手机号", max_length=11, unique=True)
    image = models.ImageField(verbose_name="头像", upload_to="head_img/%Y%m", default="default_head_img.jpg")

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        if self.nick_name:
            return self.nick_name
        else:
            return self.username
